const USER_KEY = '__USER_INFO_';
const cookie = {
    get: function(name) {
        var arr,
            reg = new RegExp("(^| )" + name + "=([^;]*)(;|$)");
        if (arr = document.cookie.match(reg))
            return unescape(arr[2]);
        else
            return null;
    },
    set: function(name, value, expires,path) {
        expires = expires || 1;

        var exp = new Date();
        exp.setTime(exp.getTime() + expires * 60 * 60 * 1000); //默认一小时
        document.cookie = name + "=" + escape(value) + ";path="+path+";expires=" + exp.toGMTString();
    },
    remove: function(name) {
    	this.set(name,'',-1);
    }
}
export default {
	login(token,isWechat){
        cookie.set(USER_KEY,token,2,'/');
    // if(isWechat){
        //     cookie.set(USER_KEY,token,2,'/');
        // }else{
		    //     localStorage.setItem(USER_KEY,token)
        // }
	},
	logout(){
		//delete localStorage.removeItem(USER_KEY);
		cookie.remove(USER_KEY);
	},
	getToken(){
    return cookie.get(USER_KEY)
		return localStorage[USER_KEY] || cookie.get(USER_KEY);
	}
}

